package com.magic.smartcity.view.more.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.TransitionOptions
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.magic.smartcity.R
import com.magic.smartcity.beans.ActivityComment
import com.magic.smartcity.databinding.ItemActivityDetailCommentBinding
import com.magic.smartcity.utils.Constant

/**
 * @description:
 * @create: Create by Magic on 2022/2/16.
 */
class ActivityDetailCommentAdapter :
    RecyclerView.Adapter<ActivityDetailCommentAdapter.ItemHolder>() {

    private val TAG: String = "ActivityDetailCommentAdapter"

    private val list: MutableList<ActivityComment> = mutableListOf()

    fun setData(datas: List<ActivityComment>) {
        list.clear()
        list.addAll(datas)
        notifyDataSetChanged()
    }

    class ItemHolder(binding: ItemActivityDetailCommentBinding) :
        RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val binding = DataBindingUtil.inflate<ItemActivityDetailCommentBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_activity_detail_comment,
            parent, false
        )
        return ItemHolder(binding)
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        Glide.with(holder.binding.imageView3).load(Constant.Service_IP + list[position].avatar)
            .error(R.color.gray).apply(RequestOptions.bitmapTransform(CircleCrop())).into(holder.binding.imageView3)
        holder.binding.comment = list[position]
    }

    override fun getItemCount() = list.size
}